import { useState, createContext, useContext } from "react";

const myConText = createContext();

function B() {
  const msg = useContext(myConText);
  return (
    <div>
      <h3>BBB --- {msg}</h3>
    </div>
  );
}

function A() {
  return (
    <div>
      <B />
    </div>
  );
}

export default function index() {
  const [msg, setMsg] = useState("Index 组件中的数据");

  return (
    <div>
      <myConText.Provider value={msg}>
        <A />
      </myConText.Provider>
    </div>
  );
}
